package com.negocio.entidades;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.validator.Min;

@Entity
@Table(name="ProvaAluno")
@IdClass(value=ProvaAlunoPK.class)
public class ProvaAluno implements Serializable{
	@Id
	@ManyToOne
	@JoinColumn(nullable=false)
	private Usuario aluno;
	
	@Id
	@ManyToOne
	@JoinColumn(nullable=false)
	private Prova prova;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable=false)
	private Date dtInicio;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable=false)
	private Date dtFim;
	
	
	@Min(0)
	@Column(nullable=true)
	private double nota;
	
	@Column(nullable=false)
	private boolean status;

	public Usuario getAluno() {
		return aluno;
	}

	public void setAluno(Usuario aluno) {
		this.aluno = aluno;
	}

	public Prova getProva() {
		return prova;
	}

	public void setProva(Prova prova) {
		this.prova = prova;
	}

	public Date getDtInicio() {
		return dtInicio;
	}

	public void setDtInicio(Date dtInicio) {
		this.dtInicio = dtInicio;
	}

	public Date getDtFim() {
		return dtFim;
	}

	public void setDtFim(Date dtFim) {
		this.dtFim = dtFim;
	}

	public double getNota() {
		return nota;
	}

	public void setNota(double nota) {
		this.nota = nota;
	}

	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}
	
	@Override
	public boolean equals(Object p){
		if(p instanceof ProvaAlunoPK){
			final ProvaAlunoPK pPK = (ProvaAlunoPK) p;
			if(!(pPK.getAluno().getId() == this.aluno.getId() && pPK.getProva().getId() == this.prova.getId())){
				return false;
			}
			return true;
		}
		return false;
	}
	
	
	@Override
	public int hashCode(){
		return this.hashCode();
	}
}
